<template>
  <el-dialog
      v-model="centerDialogVisible"
      :title="formTitle"
      width="20%"
      destroy-on-close
      center
      @close="dialogClose">
    <el-form
        ref="ruleFormRef"
        label-position="top"
        label-width="100px"
        :model="formLabelAlign"
        :rules="rules"
    >
      <el-form-item label="负责人" prop="headName">
        <el-input v-model="formLabelAlign.headName"/>
      </el-form-item>
      <el-form-item label="联系电话" prop="headPhone">
        <el-input v-model="formLabelAlign.headPhone"/>
      </el-form-item>
      <el-form-item label="地址" prop="headAddress">
        <el-input v-model="formLabelAlign.headAddress"/>
      </el-form-item>
    </el-form>
    <div class="bottomButton">
      <el-button class="affirm" @click="centerDialogVisible = false" style="width: 47.5%;height: 100%;">取消</el-button>
      <el-button class="affirm" @click="resetForm" style="width: 47.5%;height: 100%;">确认</el-button>
    </div>
  </el-dialog>

</template>

<script>
let me;
export default {
  name: "AddPrincipalDialog",
  data() {
    return {
      formTitle: '',
      rules: {
        headAddress: [
          {required: true, message: '不能为空', trigger: 'blur'}
        ],
        headPhone: [
          {required: true, message: '不能为空', trigger: 'blur'}
        ],
        headName: [
          {required: true, message: '不能为空', trigger: 'blur'}
        ]
      },
      formLabelAlign: {
        headName: '',
        headPhone: '',
        headAddress: ''
      },
      centerDialogVisible: false
    }
  },
  methods: {
    showDialog(row) {
      me = this;
      this.formTitle = '新增负责人信息';
      if (row) {
        me.formLabelAlign = JSON.parse(JSON.stringify(row));
        this.formTitle = '编辑负责人信息';
      }
      this.centerDialogVisible = true;
    },
    resetForm() {
      me.$refs.ruleFormRef.validate(async (valid, fields) => {
        if (valid) {
          let response = await me.$asyncPost("sysMenu", {actionType: "sysMenuQuery", sysMenuType: 1});
          if (response.success) {
            me.$message.success('添加成功');
            me.visible = false;
            me.$parent.selTableData();
          }
        } else {
          console.log('error submit!', fields)
        }
      })
    },
    dialogClose() {
      this.$refs.ruleFormRef.resetFields();//关闭的时候一定要清空之前的form表单已填写的数据！！！！！
    }
  }
}
</script>

<style scoped lang="scss">

</style>